import { ChangeDetectorRef, Component, Inject } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { EntityComponent } from '../../components/entity/entity.component';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { EntityType } from '@shared/models/entity-type.models';
import { NULL_UUID } from '@shared/models/id/has-uuid';
import { ActionNotificationShow } from '@core/notification/notification.actions';
import { TranslateService } from '@ngx-translate/core';
import { VideoInfo } from '@app/shared/models/video.models';
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
import { HttpClient } from '@angular/common/http';
import { MediaInfo } from '@app/shared/models/media.models';

@Component({
  selector: 'tb-video',
  templateUrl: './video-conf.component.html',
  styleUrls: ['./video-conf.component.scss']
})
export class VideoConfComponent extends EntityComponent<VideoInfo> {

  entityType = EntityType;

  videoScope: 'tenant' | 'customer' | 'customer_user';
  typechange(e) {
    
      this.entityForm.patchValue({'camNumber': '',
      'videoFactory':'',
      videoStream:'',
      streamId:''



  });
    
    
  };

  constructor(
    private http: HttpClient,
    protected store: Store<AppState>,
    protected translate: TranslateService,
    @Inject('entity') protected entityValue: VideoInfo,
    protected cd: ChangeDetectorRef,
    @Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<VideoInfo>,
    public fb: FormBuilder) {
    // super(store, fb, entityValue, entitiesTableConfigValue);
    super(store, fb, entityValue, entitiesTableConfigValue, cd);
  }
  imgpath: string;

 //streamTypes: MediaInfo[];
  ngOnInit() {
    // this.videoScope = this.entitiesTableConfig.componentsData.videoScope;
    // super.ngOnInit();
    // this.http.get<any>(`/api/v1/stream/list?pageSize=100&page=0`).subscribe(e => {
    //   this.streamTypes = e.data
    // })
  }

  hideDelete() {
    return false;
  }

  isAssignedToCustomer(entity: VideoInfo): boolean {
    return entity && entity.customerId && entity.customerId.id !== NULL_UUID;
  }

  buildForm(entity: VideoInfo): FormGroup {
    return this.fb.group(
      {
        name: [entity ? entity.name : '', []],
        ip: [entity ? entity.ip : '', []],
        orgName: [entity ? entity.orgName : '', []],
        orgCode: [entity ? entity.orgCode : '', []],
        cameraId: [entity ? entity.orgCode : '', []],

        //视频封面
        // private String cover;
        // cover: [entity ? entity.cover : '', []],
        // //视频名字
        // // private String name;
        // name: [entity ? entity.name : '', []],
        // //视频流获取方式
        // // private Integer access;
        // access: [(entity && entity.access) ? entity.access : 1, []],
        // //所属组织
        // // private String affOrgan;
        // affOrgan: [entity ? entity.affOrgan : '', []],

        // //视频厂家
        // // private String videoFactory;
        // videoFactory: [entity ? entity.videoFactory : '', []],
        // //流媒体Id 
        // // private String streamId;
        // streamId: [entity ? entity.streamId : '', []],
        // // private Integer streamType;
        // streamType: [(entity && entity.streamType) ? entity.streamType : 1, []],
        // // private Integer playProtocol;
        // playProtocol: [(entity && entity.playProtocol) ? entity.playProtocol : 1, []],
        // // private String monId;
        // // monId:[entity ? entity.monId : '', []],
        // //摄像头编号
        // // private String camNumber;
        // camNumber: [entity ? entity.camNumber : '', []],
        // //视频流  
        // // private String videoStream;
        // videoStream: [entity ? entity.videoStream : '', []],
      }
    );
  }

  updateForm(entity: VideoInfo) {
    Object.keys(entity).forEach(i => {
      this.entityForm.patchValue({ [i]: entity[i] });
    })
  }


  onAssetIdCopied($event) {
    this.store.dispatch(new ActionNotificationShow(
      {
        message: this.translate.instant('asset.idCopiedMessage'),
        type: 'success',
        duration: 750,
        verticalPosition: 'bottom',
        horizontalPosition: 'right'
      }));
  }
}
